<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>对账单</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../global/layui/css/layui.css">
</head>
<body>
<div>
    <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
        <header style="height: 100%">
            <div align="left">
                    <div class="layui-tab">
                    <ul class="layui-tab-title">
                        <li id="tab1" lay-id="11" class="layui-this" onclick="chageTab(1)">日账单</li>
                        <li id="tab2" lay-id="22" onclick="chageTab(2)">月账单</li>
                    </ul>
                </div>
            </div>
        </header>
        <div>
            <div class="widget-body no-padding">
                <table id="dt-table" class="table table-striped table-bordered table-hover" style="width:100%">
                    <thead>
                    <tr>
                    </tr>
                    <tr>
                        <th style="width: 10%">时间</th>
                        <th style="width: 10%">收入</th>
                        <th style="width: 10%">支出</th>
                        <th style="width: 10%">账户余额</th>
                        <th style="width: 10%">操作</th>
                        <th style="width: 10%;display: none">userId</th>
                    </tr>
                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
</body>
</html>

<script type="text/javascript" src="../../global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="../../global/js/jq.js"></script>
<script type="text/javascript" src="../../global/js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../global/js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../global/layui/layui.js"></script>
<script type="text/javascript" src="../../global/js/my/permission.js"></script>
<script type="text/javascript">
    //注意:选项卡 依赖 element 模块,否则无法进行功能性操作
    layui.use('element', function(){
        var $ = layui.jquery
        var element = layui.element;
        //触发事件

    });
    var pers = checkPermission();

    var example;
    var userId;

    var type = 1;

    function init() {
        example =
            $('#dt-table').DataTable({
                "searching": false,
                "processing": false,
                "serverSide": true,
                "language": {
                    "url": "/global/js/plugin/datatables/Chinese.lang"
                },

                "ajax": {
                    "url": "/clyjShopProperty/selectShopPropertyStatements",
                    "type": "get",
                    "dataType": "json",
                    "contentType": "application/json;charset=utf-8",
                    "data": function (d) {
                        d.type = type;
                    },
                    "error": function (xhr, textStatus, errorThrown) {
                        var msg = xhr.responseText;
                        console.log(msg);
                        var response = JSON.parse(msg);
                        var code = response.code;
                        var message = response.message;
                        if (code == 400) {
                            layer.msg(message);
                        } else if (code == 401) {
                            localStorage.removeItem("token");
                            layer.msg("token过期,请先登录", {shift: -1, time: 1000}, function () {
                                location.href = '/login.html';
                            });
                        } else if (code == 403) {
                            console.log("未授权:" + message);
                            layer.msg('未授权');
                        } else if (code == 500) {
                            layer.msg('系统错误:' + message);
                        }
                    }
                },
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'col-sm-10 col-xs-12 hidden-xs'i><'col-xs-12 col-sm-10' p v>>",
                "columns": [
                    {"data": "time","defaultContent": ""},
                    {
                        "data": "income",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            if(data == null)return 0 ;
                            else return data;
                        }
                    },
                    {
                        "data": "expend",
                        "defaultContent": "",
                        "render": function (data, type, row) {
                            if(data == null)return 0 ;
                            else return data;
                        }
                    },
                    {"data": "accout","defaultContent": ""},
                    {
                        "data": "",
                        "defaultContent": "",
                        "orderable": false,
                        "render": function (data, type, row) {
                            return  "<button id='editrow' class='btn btn-primary' type='button'  onclick='createStatementsExcel()' style='display: block;margin: 0 auto;text-align: center'><i class='fa fa-edit'></i>导出</button>"
                        }
                    },
                    {"data": "userId","defaultContent": "","visible": false,
                        "render": function (data, type, row) {
                            userId = data;
                        }
                    },
                ],
                "order": [[2, "desc"]]
            });
    }

    layui.use('layer', function () {
        var layer = layui.layer;
    });

    function chageTab(chagetype){
        type = chagetype;
        example.ajax.reload();

    }
    function createStatementsExcel() {
        location.href="/clyjShopProperty/createStatementsExcel?type="+1+"&userId="+userId;
    };

    init();
</script>